package com.power.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.power.DlykServerApplication;
import com.power.enu.DicEnum;
import com.power.model.TProduct;

import java.util.List;

public class IntentionProductConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        //cellData是读取到excel中的类容，
        String cellDataContent = cellData.getStringValue();
        List<TProduct> tProductList = (List<TProduct>) DlykServerApplication.cacheMap.get(DicEnum.PRODUCT.getCode());
        TProduct tProduct = tProductList.stream().filter(item -> {
            return cellDataContent.equals(item.getName());
        }).findFirst().get();
        return tProduct.getId();
    }
}
